package com.pzy.expiration.controller;

import com.pzy.expiration.model.FoodItem;
import com.pzy.expiration.model.MedicineItem;
import com.pzy.expiration.model.DailyItem;
import com.pzy.expiration.model.User;
import com.pzy.expiration.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    private UserService userService;

    // 注册接口
    @PostMapping("/register")
    public User register(@RequestParam String username, @RequestParam String password) {
        return userService.register(username, password);
    }

    // 登录接口
    @PostMapping("/login")
    public User login(@RequestParam String username, @RequestParam String password) {
        return userService.login(username, password);
    }

    // 获取食品列表
    @GetMapping("/food-items")
    public List<FoodItem> getFoodItems(@RequestParam Long userId) {
        User user = new User();
        user.setId(userId);
        return userService.getFoodItemsForUser(user);
    }

    // 获取药品列表
    @GetMapping("/medicine-items")
    public List<MedicineItem> getMedicineItems(@RequestParam Long userId) {
        User user = new User();
        user.setId(userId);
        return userService.getMedicineItemsForUser(user);
    }

    // 获取生活用品列表
    @GetMapping("/daily-items")
    public List<DailyItem> getDailyItems(@RequestParam Long userId) {
        User user = new User();
        user.setId(userId);
        return userService.getDailyItemsForUser(user);
    }
}
